﻿/*
 * Copyright © 2020, Wuxi Safover Intelligent Technology Co., Ltd. All rights reserved.
 * 
 * 无锡安永智能科技有限公司版权所有，未经许可，不得用于商业用途
 * 
 * Visit: https://www.safover.com/ 
 */

using System;

namespace Safover.LidarCollector.Models
{
    public abstract class BlindSectorConfig
    {
        public abstract float MaxValue { get; }
        public float MinValue { get; } = 0;

        public float StartAngle { get; set; }

        public float BlindAngle { get; set; }

        public float EndAngle
        {
            get
            {
                return StartAngle + BlindAngle;
            }
        }

        public BlindSectorConfig(float startAngle, float blindAngle)
        {
            Verify(startAngle, EndAngle);

            StartAngle = startAngle;
            BlindAngle = blindAngle;
        }

        public override string ToString()
        {
            return $"StartAngle=[{StartAngle}], EndAngle=[{StartAngle + BlindAngle}], BlindAngle=[{BlindAngle}].";
        }

        public bool IsInside(float angle)
        {
            return angle >= StartAngle && angle <= EndAngle;
        }

        private void Verify(float startAngle, float blindAngle)
        {
            if (MinValue > startAngle || MaxValue < startAngle)
            {
                throw new ArgumentOutOfRangeException($"Invalid start angle=[{startAngle}], allowed: Min=[{MinValue}], Max=[{MaxValue}].");
            }

            if (MinValue > blindAngle || MaxValue < blindAngle)
            {
                throw new ArgumentOutOfRangeException($"Invalid start angle=[{blindAngle}], allowed: Min=[{MinValue}], Max=[{MaxValue}].");
            }

            if (startAngle + blindAngle > MaxValue) 
            {
                throw new ArgumentOutOfRangeException($"startAngle + blindAngle = {startAngle + blindAngle} should be smaller or equal to {MaxValue}.");
            }
        }
    }
}
